import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';
export namespace PerBusinessFamilyOperationApi {
  /** 经营活动业务表信息 */
  export interface BusinessFamilyOperation {
    id: number; // 主键ID
    busiId?: string; // 业务主表ID
    familyOperationId: number; // 正式表ID，对应 per_family_operation.id，用于修改或删除时关联
    employeeId?: number; // 人员ID，对应 per_employee.id
    relation: string; // 与本人关系（称谓）
    systemPersonId: number; // 系统人员ID，对应 system_person.id
    familyName: string; // 姓名
    cardType: string; // 证件类型
    familyIdcard: string; // 证件号码
    workUnit: string; // 工作单位
    position: string; // 职务
    enterpriseName: string; // 企业名称
    operateAddress: string; // 经营地
    isRelatedBusiness: number; // 是否从事与教育相关的经营活动（1：是，0：否）
    hasEconomicRelation: number; // 是否与领导干部所在单位/系统直接发生经济关系（1：是，0：否）
    remark: string; // 备注
    status: number; // 状态（1：有效，0：无效）
    changeType: string; // 变更类型（add：新增，update：修改，delete：删除）
    changeContent: string; // 变更内容(JSON格式，仅修改时记录差异)
    auditStatus: number; // 审核状态（0 草稿 1 审核中 2 审核完成）
    finalAuditStatus: number; // 最终审核状态（0 待审核 1 审核通过 2 审核不通过）
    auditTime: string | Dayjs; // 审核完成时间
    auditor: string; // 审核人
    auditComment: string; // 审核意见
    metadata: string; // 其他参数
  }
}

/** 查询经营活动业务表分页 */
export function getBusinessFamilyOperationPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    PageResult<PerBusinessFamilyOperationApi.BusinessFamilyOperation>
  >('/per/business-family-operation/page', data, { desensitize, encrypt });
}

/** 查询经营活动业务表详情 */
export function getBusinessFamilyOperation(params: { id: number }) {
  return requestClient.get<PerBusinessFamilyOperationApi.BusinessFamilyOperation>(
    `/per/business-family-operation/get?id=${params.id}`,
  );
}

/** 新增经营活动业务表 */
export function createBusinessFamilyOperation(
  data: PerBusinessFamilyOperationApi.BusinessFamilyOperation,
) {
  return requestClient.post('/per/business-family-operation/create', data);
}

/** 修改经营活动业务表 */
export function updateBusinessFamilyOperation(
  data: PerBusinessFamilyOperationApi.BusinessFamilyOperation,
) {
  return requestClient.put('/per/business-family-operation/update', data);
}

/** 删除经营活动业务表 */
export function deleteBusinessFamilyOperation(params: { id: number }) {
  return requestClient.delete(
    `/per/business-family-operation/delete?id=${params.id}`,
  );
}

/** 批量删除经营活动业务表 */
export function deleteBusinessFamilyOperationList(ids: number[]) {
  return requestClient.delete(
    `/per/business-family-operation/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出经营活动业务表 */
export function exportBusinessFamilyOperation(params: any) {
  return requestClient.download('/per/business-family-operation/export-excel', {
    params,
  });
}

/** 根据业务主表id去查询业务数据 */
export function getFamilyOperationBusiId(data: any) {
  return requestClient.post<PerBusinessFamilyOperationApi.BusinessFamilyOperation>(
    '/per/business-family-operation/getFamilyOperationBusiId',
    data,
  );
}

/** 获取当前登录人从事经营活动 */
export function getCurrentFamilyOperation(
  data,
  desensitize: boolean,
  encrypt?: boolean,
) {
  return requestClient.post<
    List<PerBusinessFamilyOperationApi.BusinessFamilyOperation>
  >('/per/business-family-operation/getCurrentFamilyOperation', data, {
    desensitize,
    encrypt,
  });
}
